package com.ase.redislike.mapstruct.controller;

import com.ase.redislike.mapstruct.dto.MemberDto;
import com.ase.redislike.mapstruct.dto.OrderDto;
import com.ase.redislike.mapstruct.mapper.MemberMapper;
import com.ase.redislike.mapstruct.mapper.OrderMapper;
import com.ase.redislike.mapstruct.po.Member;
import com.ase.redislike.mapstruct.po.Order;
import com.ase.redislike.common.result.CommonResult;
import com.ase.redislike.common.result.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author： yuhang
 * @Date： 2021/11/9
 * @Description：
 */
@RestController
@Api(tags = "MapStructController", description = "MapStruct对象转换测试")
@RequestMapping("/mapStruct")
public class MapStructController {

    @ApiOperation(value = "基本映射")
    @GetMapping("/baseMapping")
    public Response baseTest() {
        Member member = new Member();
        MemberDto memberDto = MemberMapper.INSTANCE.toDto(member);
        return CommonResult.success(memberDto);
    }

    @ApiOperation(value = "集合映射")
    @GetMapping("/collectionMapping")
    public Response collectionMapping() {
        List<Member> memberList = new ArrayList<>();
        List<MemberDto> memberDtoList = MemberMapper.INSTANCE.toDtoList(memberList);
        return CommonResult.success(memberDtoList);
    }

    @ApiOperation(value = "子对象映射")
    @GetMapping("/subMapping")
    public Response subMapping() {
        List<Order> orderList = new ArrayList<>();
        OrderDto orderDto = OrderMapper.INSTANCE.toDto(orderList.get(0));
        return CommonResult.success(orderDto);
    }
}
